Here is the entire VRML 2.0 source code. Type (or paste) this code into a file called "transtst.wrl".
#VRML V2.0 utf8 # transtst.wrl : example of a simple animation of a cone. When # it is clicked it starts/stops rotating. # Written By : John DeCuir # Sony pictures Imageworks #here is the cone DEF CONE_TRANS Transform { translation 0 3 0 children [ DEF TOUCH_SENSOR TouchSensor {} # Mouse click control DEF CONE Shape { appearance Appearance { material Material { emissiveColor 0.5 0 0 } } geometry Cone { height 2 bottomRadius 1 } } ] } #script for the animation DEF CONE_SCRIPT Script { url "transtst.class" scriptType "javabc" field SFNode the_cone_trans USE CONE_TRANS eventIn SFBool clicked eventIn SFTime move eventOut SFBool setTimerEnabled } #The all-important time event generator DEF HOURGLASS TimeSensor { loop TRUE enabled FALSE cycleInterval 0.2 stopTime -1 } #Route for the mouse click ROUTE TOUCH_SENSOR.isActive TO CONE_SCRIPT.clicked #Route for the timer to call "move" each time an event occurs ROUTE HOURGLASS.time TO CONE_SCRIPT.move #Route to enable or disable the timer ROUTE CONE_SCRIPT.setTimerEnabled TO HOURGLASS.set_enabled
Here is the Java source code. Type this into a file called "transtst.java".
/* transtst.java : example of a simple animation of a cone. When it is clicked it starts/stops rotating. Written By : John DeCuir Sony pictures Imageworks */ import vrml.*; import vs.*; public class transtst extends Script { SFNode coneTransN = (SFNode)getField("the_cone_trans"); Transform coneTrans = (Transform)coneTransN.getValue(); float newTrans[] = new float[4]; float transPt[] = new float[3]; // setTimerEnabled changes "enabled" field of the TimeSensor // since we have a set up a route to do this SFBool setTimerEnabled = (SFBool) getEventOut("setTimerEnabled"); boolean timerOn; public transtst() { timerOn = false; // set up rotation axis and angle newTrans[0] = 1; newTrans[1] = 0; newTrans[2] = 0; newTrans[3] = 10; // degrees // set up centre of rotation transPt[0] = 0; transPt[1] = 2; transPt[2] = 0; } // clicked() is called when the mouse is clicked public void clicked(ConstSFBool ev, ConstSFTime time) { if (ev.getValue() == true) { return; } else { if (timerOn == false) { setTimerEnabled.setValue(true); timerOn = true; } else { setTimerEnabled.setValue(false); timerOn = false; } } } // move() is called at each time event. It calls a Java // function which rotates the cone public void move(ConstSFTime ev, ConstSFTime time) { coneTrans.rotateAroundLineDegree(newTrans, transPt, coneTrans.modeRelative); } }